---
title: Naming Conventions
description: Overview of the recommended naming conventions when using bloc.
---

import EventExamplesGood1 from '~/components/naming-conventions/EventExamplesGood1Snippet.astro';
import EventExamplesBad1 from '~/components/naming-conventions/EventExamplesBad1Snippet.astro';
import StateExamplesGood1Snippet from '~/components/naming-conventions/StateExamplesGood1Snippet.astro';
import SingleStateExamplesGood1Snippet from '~/components/naming-conventions/SingleStateExamplesGood1Snippet.astro';
import StateExamplesBad1Snippet from '~/components/naming-conventions/StateExamplesBad1Snippet.astro';

The following naming conventions are simply recommendations and are completely optional. Feel free to use whatever naming conventions you prefer. You may find some of the examples/documentation do not follow the naming conventions mainly for simplicity/conciseness. These conventions are strongly recommended for large projects with multiple developers.

## Event Conventions

Events should be named in the **past tense** because events are things that have already occurred from the bloc's perspective.

### Anatomy

`BlocSubject` + `Noun (optional)` + `Verb (event)`

Initial load events should follow the convention: `BlocSubject` + `Started`

:::note
The base event class should be name: `BlocSubject` + `Event`.
:::

### Examples

✅ **Good**

<EventExamplesGood1 />

❌ **Bad**

<EventExamplesBad1 />

## State Conventions

States should be nouns because a state is just a snapshot at a particular point in time. There are two common ways to represent state: using subclasses or using a single class.

### Anatomy

#### Subclasses

`BlocSubject` + `Verb (action)` + `State`

When representing the state as multiple subclasses `State` should be one of the following:

`Initial` | `Success` | `Failure` | `InProgress`

:::note
Initial states should follow the convention: `BlocSubject` + `Initial`.
:::

#### Single Class

`BlocSubject` + `State`

When representing the state as a single base class an enum named `BlocSubject` + `Status` should be used to represent the status of the state:

`initial` | `success` | `failure` | `loading`.

:::note
The base state class should always be named: `BlocSubject` + `State`.
:::

### Examples

✅ **Good**

##### Subclasses

<StateExamplesGood1Snippet />

##### Single Class

<SingleStateExamplesGood1Snippet />

❌ **Bad**

<StateExamplesBad1Snippet />
